<!doctype html>
<script src='webp_dec.js'></script>
<script>
  const Module = webp_dec();

  async function loadFile(src) {
    const resp = await fetch(src);
    return await resp.arrayBuffer();
  }

  Module.onRuntimeInitialized = async _ => {
    console.log('Version:', Module.version().toString(16));
    const image = await loadFile('../example.webp');
    const result = Module.decode(image);
    const imageData = new ImageData(new Uint8ClampedArray(result.buffer), result.width, result.height);
    Module.free_result();
    const canvas = document.createElement('canvas');
    canvas.width = result.width;
    canvas.height = result.height;
    document.body.appendChild(canvas);
    const ctx = canvas.getContext('2d');
    ctx.putImageData(imageData, 0, 0);
  };
</script>
